package com.selebash;

import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

/**
 * @author sad
 */
public class Utils {

    public static String stripQuotes(String str) {
        return StringUtils.strip(str, "\"'");
    }

    public static Pair<String, Integer> selectMostApropriateString(String string, List<String> candidates) {
        int mindistance = 99999999;
        String candidate = null;
        int candidateIndex = -1;
        int index = -1;
        for (String c : candidates) {
            index++;
            int distance = StringUtils.getLevenshteinDistance(string, c);
            if (distance < mindistance) {
                mindistance = distance;
                candidate = c;
                candidateIndex = index;
            }
        }
        return new ImmutablePair<>(candidate, candidateIndex);
    }
}
